<template>
  <div>
    <el-card style="min-width: 1200px">
      <div class="tableSelectWrap">
        <el-form
          ref="withdrawRecordForm"
          :model="commandForm"
          label-width="100px"
        >
          <el-row>
            <el-col :span="7">
              <el-form-item label="选择时间" prop="date">
                <el-date-picker
                  v-model="commandForm.date"
                  style="width: 100%"
                  :default-time="['00:00:00', '23:59:59']"
                  type="datetimerange"
                  start-placeholder="开始时间"
                  end-placeholder="结束时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1">
              <el-form-item label="账务类型" prop="orderType">
                <el-select
                  v-model="commandForm.orderType"
                  clearable
                  style="width: 100%"
                  placeholder="请选择账务类型"
                >
                  <el-option
                    v-for="item of financeType"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1">
              <el-form-item label="用户ID" prop="userNo">
                <el-input
                  v-model="commandForm.userNo"
                  placeholder="请输入用户ID"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="7" style="min-width: 170px">
              <el-button
                class="width120"
                @click="
                  resetForm('withdrawRecordForm');
                "
                >重置</el-button
              >
              <el-button
                type="primary"
                class="width120"
                @click="
                  () => {
                    this.dataForm = JSON.parse(
                      JSON.stringify(this.commandForm)
                    );
                    this.handleQuery();
                  }
                "
                >查询</el-button
              >
            </el-col>
          </el-row>
        </el-form>
      </div>
    </el-card>
    <el-card
      class="textBox"
      style="min-width: 1200px; margin-bottom: -5px; margin-top: 15px"
    >
      <span class="numBox">
        <span>平台账户余额</span>
        <span class="symbol">￥</span>
        <span class="num">{{ acctBalance.fmtAmount?acctBalance.fmtAmount:'0.00'}}</span>
      </span>
    </el-card>
    <el-card style="margin-top: 15px; min-width: 1200px">
      <el-table :data="dataList" :height="fixedTableHeight">
        <template slot="empty">
          <el-empty
            :image="require('@/assets/imgs/middleWork/k1.png')"
            :image-size="80"
            description="暂无相关数据"
          ></el-empty>
        </template>
        <el-table-column
          show-overflow-tooltip
          prop="gmtCreated"
          align="center"
          label="创建时间"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.gmtCreated ? scope.row.gmtCreated : "-" }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          prop="orderNo"
          align="center"
          label="云尘付流水号"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.orderNo ? scope.row.orderNo : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="userNo"
          align="center"
          label="用户/商户ID"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.userNo ? scope.row.userNo : "-" }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          prop="orderTypeName"
          align="center"
          label="账务类型"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.orderTypeName ?scope.row.orderTypeName: "-" }}
            </div>
          </template>
        </el-table-column>

        <el-table-column
          show-overflow-tooltip
          prop="fmtChangeAmount"
          sortable
          align="center"
          label="变动金额/元"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              <span
                :class="scope.row.changeType == 'income' ? 'output' : 'income'"
                >{{
                  scope.row.changeType
                    ? scope.row.changeType == "income"
                      ? "+"
                      : "-"
                    : ""
                }}</span
              >
              <span
                :class="scope.row.changeType == 'income' ? 'output' : 'income'"
              >
                {{
                  scope.row.fmtChangeAmount
                    ? scope.row.fmtChangeAmount
                    : "-"
                }}</span
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="act"
          align="center"
          label="操作"
        >
          <!-- <template slot-scope="scope">
            <div>
              <el-button type="text" @click="handleDetails(scope.row)"
                >详情</el-button
              >
            </div>
          </template> -->
          <div>-</div>
        </el-table-column>
      </el-table>
    </el-card>
    <el-pagination
      layout="prev, pager, next, sizes, jumper"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      :current-page="pageNum"
      :total="total"
      @current-change="pageCurrentChangeHandle"
      @size-change="pageSizeChangeHandle"
    >
    </el-pagination>
    <!-- 详情抽屉 -->
    <detail-drawer
      :drawer.sync="drawer"
      :info="detailsInfo"
      :activeKey="activeKey"
    ></detail-drawer>
  </div>
</template>

<script>
import detailDrawer from "./detailDrawer.vue";
import mixin from "@/mixins/mixin";
export default {
  name: "normalBalance",
  mixins: [mixin],
  components: {
    detailDrawer,
  },
  data() {
    return {
      acctBalance: {
        fmtAmount: "",
      },
      activeKey: "1", //切换tab
      mixinViewModuleOptions: {
        getDataListURL:
          "/api/merchant/settleBalanceDrawcash/searchChangeByPage",
        createdIsNeed: false,
      },
      drawer: false,
      detailsInfo: {},
      commandForm: {
        userNo: "",
        orderType: "",
        date: [],
      },
      financeType: [
        { id: 1, label: "所有", value: "" },
        { id: 2, label: "分润", value: "settle" },
        { id: 3, label: "订单", value: "order" },
        { id: 4, label: "退款", value: "refund" },
        { id: 5, label: "转账", value: "transfer" },
        { id: 6, label: "提现", value: "withdrawal" },
        { id: 7, label: "鉴权充值", value: "charge" },
        { id: 8, label: "余额赠送", value: "balance_bonus" },
        { id: 9, label: "余额充值", value: "recharge" },
      ],
    };
  },
  created() {
    this.dataForm = JSON.parse(JSON.stringify(this.commandForm));
    this.getChannelList();
    this.handleQuery();
  },
  watch: {
    "$store.state.testLine": {
      handler() {
        if (this.$route.name == this.$options.name) {
    this.getChannelList();
          this.handleQuery();
        }
      },
    },
    deep: true,
  },
  methods: {
    getChannelList() {
      this.$http.get("/api/merchant/settleBalanceDrawcash/getBalanceAccount").then((res) => {
        if (res.code === "0000") {
          this.acctBalance.fmtAmount =res.data.fmtAmount
        }
      });
    },
    handleDetails(row) {
      switch (this.activeKey) {
        case "1":
          this.$http
            .get(
              `/api/merchant/settleBalanceDrawcash/getChangeById?id=${row.id}`
            )
            .then((res) => {
              if (res.code === "0000") {
                this.detailsInfo = res.data;
                this.drawer = true;
              }
            });
          break;
        default:
          break;
      }
    },
    handleQuery() {
      if (this.dataForm.date && this.dataForm.date.length) {
        this.dataForm.gmtCreatedBegin = this.dataForm.date[0];
        this.dataForm.gmtCreatedEnd = this.dataForm.date[1];
      } else {
        this.dataForm.gmtCreatedBegin = null;
        this.dataForm.gmtCreatedEnd = null;
      }
      this.getDataList()
    },
  },
};
</script>

<style scoped lang="scss">
.pedding {
  color: #ee8917;
}
.switch {
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
}
.ml {
  margin-left: 50px;
}
.search {
  position: absolute;
  right: 0;
  top: -164px;
}
.income {
  color: rgb(234, 78, 78);
}
.output {
  color: rgb(59, 185, 112);
}
</style>
